/*
* berton
*/
package com.pitop.supplier.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

import com.pitop.supplier.api.SupplierFeignApi;
import com.pitop.core.exceptions.SupplierException;
import com.pitop.core.exceptions.BaseException;
import com.pitop.core.entity.Page;
import com.pitop.supplier.entity.Supplier;


/**
 * 供应商
 * @author berton
 */
@Service("supplierSVImpl")
@Slf4j
public class SupplierSVImpl {

    @Autowired
    private SupplierFeignApi supplierFeignApi;

    /**
     * 加载一个对象Supplier
     * @param id * @param code 编码
     * @return Supplier
     */
    public Supplier load(java.lang.Long id,java.lang.String code) {
        if(id==null&&code==null){
            throw new SupplierException(BaseException.BaseExceptionEnum.Ilegal_Param);
        }
        return supplierFeignApi.load(id,code);
    }
    /**
     * 加载一个对象Supplier 通过id
     * @param id 
     * @return Supplier
     */
    public Supplier loadById(java.lang.Long id) {
        if(id==null){
            throw new SupplierException(BaseException.BaseExceptionEnum.Ilegal_Param);
        }
        return supplierFeignApi.loadById(id);
    }

    /**
     * 加载一个对象Supplier 通过code
     * @param code 编码
     * @return Supplier
     */
    public Supplier loadByCode(java.lang.String code) {
        if(code==null){
            throw new SupplierException(BaseException.BaseExceptionEnum.Ilegal_Param);
        }
        return supplierFeignApi.loadByCode(code);
    }


    /**
     * 删除对象Supplier
     * @param id * @param code 编码
     * @return Supplier
     */
    
    public void delete(java.lang.Long id,java.lang.String code) {
        if(id==null&&code==null){
            throw new SupplierException(BaseException.BaseExceptionEnum.Ilegal_Param);
        }
        supplierFeignApi.delete(id,code);
    }



    /**
     * 查询Supplier分页
     *
     * @param supplier  对象
     * @param curPage 当前页
     * @param pageSize 分页条数
     * @return List<Supplier>
     */
    public List<Supplier> list(Supplier supplier, int curPage,int pageSize) {
        return supplierFeignApi.list(supplier, curPage,pageSize);
    }

    /**
     * 查询Supplier分页
     *
     * @param id  * @param code  编码
     * @param curPage 当前页
     * @param pageSize 分页条数
     * @return List<Supplier>
     */
    public List<Supplier> list(java.lang.Long id,java.lang.String code,int curPage, int pageSize) {
        if (curPage < 0) {
           curPage = 1;
        }

        if (pageSize < 0) {
            pageSize = Page.limit;
        }

        Supplier supplier=new Supplier();
        supplier.setId(id);
        supplier.setCode(code);

        return supplierFeignApi.list(supplier,curPage,pageSize);
    }


    public int count(java.lang.Long id,java.lang.String code) {
        return supplierFeignApi.count(id,code);
    }


    public int count(Supplier supplier) {
        return supplierFeignApi.count(supplier);
    }


    /**
     * 保存
     *
     * @param supplier 实体
     * @throws BaseException
     */
    public void save(Supplier supplier) {
        if(supplier==null){ throw new SupplierException(BaseException.BaseExceptionEnum.Ilegal_Param);}
        supplierFeignApi.build(supplier);
    }

    /**
     * 更新
     *
     * @param supplier 实体
     * @throws BaseException
     */
    public void modify(Supplier supplier) {
        if(supplier==null){ throw new SupplierException(BaseException.BaseExceptionEnum.Ilegal_Param);}
        supplierFeignApi.modify(supplier);
    }

}
